home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Draw / Sources / RRectShp.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  8.7 KB  |  320 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                RRectShp.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef BASESHP_H
  15. #include "BaseShp.h"
  16. #endif
  17.  
  18. #ifndef BOUNDSHP_H
  19. #include "BoundShp.h"
  20. #endif
  21.  
  22. #ifndef RRECTSHP_H
  23. #include "RRectShp.h"
  24. #endif
  25.  
  26. #ifndef UTILS_H
  27. #include "Utils.h"
  28. #endif
  29.  
  30. #ifndef CONSTANT_H
  31. #include "Constant.h"
  32. #endif
  33.  
  34. #ifndef DRAWPART_H
  35. #include "DrawPart.h"
  36. #endif
  37.  
  38. #ifndef DRAWPART_H
  39. #include "DrawPart.h"
  40. #endif
  41.  
  42. #ifndef DRAWFRM_H
  43. #include "DrawFrm.h"
  44. #endif
  45.  
  46. #ifndef DRAWPRXY_H
  47. #include "DrawPrxy.h"
  48. #endif
  49.  
  50. #ifndef DRAWLINK_H
  51. #include "DrawLink.h"
  52. #endif
  53.  
  54. #ifndef DRAWCLIP_H
  55. #include "DrawClip.h"
  56. #endif
  57.  
  58. // ----- Part Layer -----
  59.  
  60. #ifndef FWFRMING_H
  61. #include "FWFrming.h"
  62. #endif
  63.  
  64. #ifndef FWUTIL_H
  65. #include "FWUtil.h"
  66. #endif
  67.  
  68. #ifndef FWSELECT_H
  69. #include "FWSelect.h"
  70. #endif
  71.  
  72. #ifndef FWITERS_H
  73. #include "FWIters.h"
  74. #endif
  75.  
  76. // ----- OS Layer -----
  77.  
  78. #ifndef FWEVENT_H
  79. #include "FWEvent.h"
  80. #endif
  81.  
  82. #ifndef FWRECSHP_H
  83. #include "FWRecShp.h"
  84. #endif
  85.  
  86. #ifndef FWTXTBOX_H
  87. #include "FWTxtBox.h"
  88. #endif
  89.  
  90. #ifndef FWLINSHP_H
  91. #include "FWLinShp.h"
  92. #endif
  93.  
  94. #ifndef FWOVLSHP_H
  95. #include "FWOvlShp.h"
  96. #endif
  97.  
  98. #ifndef FWRRCSHP_H
  99. #include "FWRRcShp.h"
  100. #endif
  101.  
  102. #ifndef FWODGEOM_H
  103. #include "FWODGeom.h"
  104. #endif
  105.  
  106. #ifndef FWGRUTIL_H
  107. #include "FWGrUtil.h"
  108. #endif
  109.  
  110. // ----- Foundation Includes -----
  111.  
  112. #ifndef FWSTREAM_H
  113. #include "FWStream.h"
  114. #endif
  115.  
  116. // ----- OpenDoc Includes -----
  117.  
  118. #ifndef SOM_ODTransform_xh
  119. #include <Trnsform.xh>
  120. #endif
  121.  
  122. //========================================================================================
  123. // Runtime Information
  124. //========================================================================================
  125.  
  126. #ifdef FW_BUILD_MAC
  127. #pragma segment odfdrawshapes
  128. #endif
  129.  
  130. //========================================================================================
  131. // RunTime Info
  132. //========================================================================================
  133.  
  134. FW_DEFINE_AUTO(CRoundRectShape)
  135. FW_DEFINE_CLASS_M1(CRoundRectShape, CBoundedShape)
  136.  
  137. const FW_ClassTypeConstant LRoundRectShape = FW_TYPE_CONSTANT('s','h','r','r');
  138. FW_REGISTER_ARCHIVABLE_CLASS(LRoundRectShape, CRoundRectShape, CRoundRectShape::Read, 0, 0, CBaseShape::Write)
  139.  
  140. //========================================================================================
  141. // class CRoundRectShape
  142. //========================================================================================
  143.  
  144. //----------------------------------------------------------------------------------------
  145. // CRoundRectShape::CRoundRectShape
  146. //----------------------------------------------------------------------------------------
  147.  
  148. CRoundRectShape::CRoundRectShape(CDrawPart* drawPart, FW_Fixed radius, FW_Boolean roundEnds):
  149.     CBoundedShape(drawPart, kRRectShape, kFrameOnly),
  150.     fRadius(radius),
  151.     fRoundEnds(roundEnds)
  152. {
  153.     FW_END_CONSTRUCTOR
  154. }
  155.  
  156. //----------------------------------------------------------------------------------------
  157. // CRoundRectShape::CRoundRectShape
  158. //----------------------------------------------------------------------------------------
  159.  
  160. CRoundRectShape::CRoundRectShape(CDrawPart* drawPart, FW_CReadableStream& archive) :
  161.     CBoundedShape(drawPart, archive)
  162. {    
  163.     archive >> fRadius;
  164.     archive >> fRoundEnds;
  165.     
  166.     FW_END_CONSTRUCTOR
  167. }
  168.  
  169. //----------------------------------------------------------------------------------------
  170. // CRoundRectShape::~CRoundRectShape
  171. //----------------------------------------------------------------------------------------
  172.  
  173. CRoundRectShape::~CRoundRectShape()
  174. {
  175.     FW_START_DESTRUCTOR
  176. }
  177.  
  178. //----------------------------------------------------------------------------------------
  179. // CRoundRectShape::OutlineShape
  180. //----------------------------------------------------------------------------------------
  181.  
  182. void CRoundRectShape::OutlineShape(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style, const FW_CRect& rect)
  183. {
  184.     FW_CRect bounds(rect);
  185.     AdjustRectForPenSize(bounds, style.GetPenSize());
  186.  
  187.     FW_CRoundRectShape::RenderRoundRect(gc,
  188.                                       bounds,
  189.                                     GetOvalSize(bounds),
  190.                                       FW_kFrame,
  191.                                       ink, style);
  192. }
  193.  
  194. //----------------------------------------------------------------------------------------
  195. // CRoundRectShape::RenderShape
  196. //----------------------------------------------------------------------------------------
  197.  
  198. void CRoundRectShape::RenderShape(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc)
  199. {
  200. FW_UNUSED(ev);
  201. FW_UNUSED(facet);
  202.     FW_CRect rect = GetRectGeometry();
  203.     AdjustRectForPenSize(rect, GetPenSize());
  204.  
  205.     FW_CPoint ovalSize = GetOvalSize(rect);
  206.     
  207.     if (HasFillStyle())
  208.         FW_CRoundRectShape::RenderRoundRect(gc, rect, ovalSize, FW_kFill, fFillInk, fFillStyle);
  209.     
  210.     if (HasFrameStyle())
  211.         FW_CRoundRectShape::RenderRoundRect(gc, rect, ovalSize, FW_kFrame, fFrameInk, fFrameStyle);
  212. }
  213.  
  214. //----------------------------------------------------------------------------------------
  215. // CRoundRectShape::GetOvalSize
  216. //----------------------------------------------------------------------------------------
  217.  
  218. FW_CPoint CRoundRectShape::GetOvalSize(const FW_CRect& bounds) const
  219. {
  220.     FW_CPoint ovalSize(fRadius, fRadius);
  221.     
  222.     if (fRoundEnds)
  223.     {
  224.         ovalSize.x = bounds.right - bounds.left;
  225.         ovalSize.y = bounds.bottom - bounds.top;
  226.         ovalSize.x = ovalSize.y = FW_Minimum(ovalSize.x,ovalSize.y);
  227.     }
  228.     
  229.     return ovalSize;
  230. }
  231.  
  232. //----------------------------------------------------------------------------------------
  233. // CRoundRectShape::HitTest
  234. //----------------------------------------------------------------------------------------
  235.  
  236. FW_Boolean CRoundRectShape::HitTest(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent) const
  237. {    
  238.     FW_CPoint mouse = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  239.     ODFacet* facet = theMouseEvent.GetFacet(ev);
  240.     FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  241.     frame->GetContentView(ev)->FrameToViewContent(ev, mouse);
  242.  
  243.     FW_CRect bounds = GetRectGeometry();
  244.     AdjustRectForPenSize(bounds, GetPenSize());
  245.  
  246.     FW_CRoundRectShape RRectShape(bounds, GetOvalSize(bounds), HasFillStyle() ? FW_kFill : FW_kFrame);
  247.     return RRectShape.HitTest(gc, mouse, FW_IntToFixed(2));
  248. }
  249.  
  250. //----------------------------------------------------------------------------------------
  251. // CRoundRectShape::CalcClipShape
  252. //----------------------------------------------------------------------------------------
  253.  
  254. ODShape* CRoundRectShape::CalcClipShape(Environment* ev)
  255. {
  256.     FW_CRect bounds = GetRectGeometry();
  257.     AdjustRectForPenSize(bounds, GetPenSize());
  258.     
  259.     FW_CPoint ovalSize = GetOvalSize(bounds);
  260.     
  261.     FW_CAcquiredODShape clipShape = ::FW_CreateRoundRectODShape(ev, bounds, ovalSize);
  262.     
  263.     if (FrameOnly())
  264.     {
  265.         bounds.Inset(GetPenSize(), GetPenSize());
  266.         FW_CAcquiredODShape roundRectShape = ::FW_CreateRoundRectODShape(ev, bounds, ovalSize);
  267.         clipShape->Subtract(ev, roundRectShape);
  268.     }
  269.     
  270.     return clipShape.Orphan();
  271. }
  272.  
  273. //----------------------------------------------------------------------------------------
  274. // CRoundRectShape::CreateShapeOutline
  275. //----------------------------------------------------------------------------------------
  276.  
  277. ODShape* CRoundRectShape::CreateShapeOutline(Environment *ev)
  278. {
  279.     FW_CRect bounds = GetRectGeometry();
  280.     AdjustRectForPenSize(bounds, GetPenSize());
  281.     
  282.     ODShape* dragRgn = ::FW_CreateRoundRectODShape(ev, bounds, GetOvalSize(bounds));        // We don't acquire it because we return it
  283.     
  284.     ::FW_OutlineODShape(ev, dragRgn, GetPenSize());
  285.     
  286.     return dragRgn;
  287. }
  288.  
  289. //----------------------------------------------------------------------------------------
  290. // CRoundRectShape::Read
  291. //----------------------------------------------------------------------------------------
  292.  
  293. void* CRoundRectShape::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  294. {
  295. FW_UNUSED(type);
  296.     // [HLX] This is a hack until I can register object with the archiver
  297.     CDrawReadableStream *drawArchive = (CDrawReadableStream*)&stream;
  298.     return FW_NEW(CRoundRectShape, (drawArchive->GetDrawPart(), stream));
  299. }
  300.  
  301. //----------------------------------------------------------------------------------------
  302. // CRoundRectShape::Flatten
  303. //----------------------------------------------------------------------------------------
  304.  
  305. void CRoundRectShape::Flatten(FW_CWritableStream& archive)
  306. {    
  307.     CBoundedShape::Flatten(archive);
  308.     archive << fRadius;
  309.     archive << fRoundEnds;
  310. }
  311.  
  312. //----------------------------------------------------------------------------------------
  313. // CRoundRectShape::GetObjectClass
  314. //----------------------------------------------------------------------------------------
  315.  
  316. ODDescType CRoundRectShape::GetObjectClass() const
  317. {
  318.     return cRoundedRectangle;
  319. }
  320.